def f(n) :
        for i in range(2,n) :
            if n%i==0:
                return 0
            return 1
n=int(input("Введите число"))
if n<1000 or n>=10000:
    print(0)
else:
    if f(n) :
        m=n
    else :
        m=0
        while n!=0 :
            x=n%10
            y=n%100
            z=n%1000
            if f(x): m=max (m,x)
            if f(y): m = max (m,y)
            if f(x): m = max(m,z)
            a//=10
            print(m)
